//
//  SNFriendVc.m
//  project
//
//  Created by 黄建华 on 2018/8/9.
//  Copyright © 2018年 黄建华. All rights reserved.
//

#import "SNFriendVc.h"
#import "SNSearchFriendVc.h"
#import "FriendSelectSegView.h"
#import "FriendSystemMessageTb.h"
#import "FriendRequestTb.h"
#import "FriendListTb.h"
#import "SNFriendDetailVc.h"
#import "SNFriendShareVc.h"
#import "SNFriendInfoVc.h"

@interface SNFriendVc ()
@property (nonatomic, strong) FriendSelectSegView   *selectSeg;
@property (nonatomic, strong) FriendSystemMessageTb *showView1;
@property (nonatomic, strong) FriendRequestTb       *showView2;
@property (nonatomic, strong) FriendListTb          *showView3;
@property (nonatomic, assign) NSInteger             selectType;
@property (nonatomic, strong) NSMutableArray        *friendInvArray;

@end

@implementation SNFriendVc

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    UIView *StateView = [[UIView alloc] init];
    StateView.frame           = CGRectMake(0, 0, kSCREEN_WIDTH, 20);
    StateView.backgroundColor = BBIGSTATECOLOR;
    [self.view addSubview:StateView];
    
    UIView *naView = [[UIView alloc] init];
    naView.frame           = CGRectMake(0, 20+FitSimpleIpx(0, 20), kSCREEN_WIDTH, 44);
    naView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:naView];
    
    UILabel *lable = [[UILabel alloc]initWithFrame:CGRectMake(0, 20+FitSimpleIpx(0, 20), screenWidth, 44)];
    lable.textColor     = [UIColor blackColor];
    lable.font          = SNFONT(17);
    lable.textAlignment = NSTextAlignmentCenter;
    lable.text          = HHH_Text(@"我的好友");
    
    [self.view addSubview:lable];

    UIButton *leftButton = [[UIButton alloc] init];
    leftButton.frame = CGRectMake(5, 20+FitSimpleIpx(0, 20), 44, 44);
    [leftButton setImageNormal:@"进入"];
    [leftButton addTarget:self action:@selector(backButton) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:leftButton];
    
    UIImageView *shadowLine = [[UIImageView alloc] init];
    shadowLine.frame = SNFRAME(0, 20+FitSimpleIpx(0, 20) + 44 -2, HHHWIDTH, 2);
    shadowLine.image = [UIImage image:@"lineImage"];
    [self.view addSubview:shadowLine];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    UIButton *addFriendButton = [UIButton buttonWithType:UIButtonTypeCustom];
    addFriendButton.frame = CGRectMake(screenWidth - 44 -5, 33 + FitSimpleIpx(0, 20), 44, 44);
    [addFriendButton setImageNormal:@"添加好友"];
    addFriendButton.imageEdgeInsets = UIEdgeInsetsMake(2, 2, 4, 2);
    addFriendButton.center          = CGPointMake(screenWidth - 22 -10, leftButton.centerY);
    [self.view addSubview:addFriendButton];
    [addFriendButton addTarget:self action:@selector(addFriendButtonClick) forControlEvents:UIControlEventTouchUpInside];
    
    _selectSeg = [[FriendSelectSegView alloc] initWithFrame:SNFRAME(0, shadowLine.bottom +5, screenWidth, 50)];
    [self.view addSubview:_selectSeg];
    _selectType = 1;
    DEF_WEAKSELF_(SNFriendVc)
    _selectSeg.selectType = ^(NSInteger type) {
        [weakSelf selectType:type];
    };
    
    UIButton *invButton = [[UIButton alloc] init];
    [invButton setTitle:SN_Text(@"邀请好友") forState:UIControlStateNormal];
    [invButton setTitleColor:SNCOLORWHITE forState:UIControlStateNormal];
    [invButton setTitleColor:SNCOLORGRAY forState:UIControlStateHighlighted];
    invButton.backgroundColor     = SNCOLORBLACK;
    invButton.frame               = SNFRAME(20, HHHHEIGHT - 55, screenWidth - 40, 44);
    invButton.layer.cornerRadius  = 5.0;
    invButton.layer.masksToBounds = YES;
    [invButton addTarget:self action:@selector(invFriend) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:invButton];
    
    // 初始化三个View
    _showView1 = [[FriendSystemMessageTb alloc] initWithFrame:SNFRAME(0, _selectSeg.bottom, screenWidth, invButton.top - _selectSeg.bottom - 2)];
    [self.view addSubview:_showView1];
    
    _showView2 = [[FriendRequestTb alloc] initWithFrame:SNFRAME(0, _selectSeg.bottom, screenWidth, _showView1.height)];
    [self.view addSubview:_showView2];
    
    _showView3 = [[FriendListTb alloc] initWithFrame:SNFRAME(0, _selectSeg.bottom, screenWidth, _showView1.height)];
    [self.view addSubview:_showView3];
    
    _showView1.selectBlock = ^(FriednInviterModel *model)
    {
        [weakSelf FriendInfo:model];
    };
    
    _showView2.selectBlock = ^(FriednInviterModel *model)
    {
        [weakSelf FriendInfo:model];
    };
    
    _showView3.selectFriendBlock = ^(FriednInviterModel *model)
    {
        [weakSelf selectFriendInfo:model];
    };
    
    [self selectType:1];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
}

- (void)FriendInfo:(FriednInviterModel *)model {
    SNFriendInfoVc *vc = [[SNFriendInfoVc alloc] init];
    vc.model = model;
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)selectFriendInfo:(FriednInviterModel *)model {
    NSLog(@"我的好友详情 >>>>>%@", model.nickName);
    SNFriendDetailVc *vc = [[SNFriendDetailVc alloc] init];
    vc.model = model;
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)selectType:(NSInteger)type {
    _selectType = type;
    NSLog(@"添加好友>>>>%d", type);
    _showView1.hidden = YES;
    _showView2.hidden = YES;
    _showView3.hidden = YES;
    
    if (type == 1) {
        _showView1.hidden = NO;
    }
    if (type == 2) {
        _showView2.hidden = NO;
    }
    if (type == 3) {
        _showView3.hidden = NO;
    }
    
    if (_selectType == 1) {
        [_showView1 updateFriendRequest];
    }
    if (_selectType == 2) {
        [_showView2 updateFriendRequest];
    }
    if (_selectType == 3) {
        [_showView3 updateFriendRequest];
    }
}

- (void)addFriendButtonClick {
    SNSearchFriendVc *vc = [[SNSearchFriendVc alloc] init];
    
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)backButton {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)invFriend {
    SNFriendShareVc *vc = [[SNFriendShareVc alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
